﻿@model ZSZ.DTO.PermissionDTO[]
@{
    ViewBag.Title = "添加角色";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<form id="formData">
    <div class="row cl">
        <label class="form-label col-3"><span class="c-red">*</span>角色名：</label>
        <div class="formControls col-5">
            <input type="text" class="input-text" name="name" id="name" datatype="*1-50" nullmsg="角色名称不能为空" />
        </div>
        <div class="col-4"> </div>
    </div>
    <div class="row cl">
        @foreach (var perm in Model)
        {
            <div class="col-xs-12 col-sm-3">
                <input type="checkbox" id="PermissionIds_@perm.Id" name="PermissionIds" value="@perm.Id" />
                <label for="PermissionIds_@perm.Id">@perm.Description</label>
            </div>
        }
    </div>
    <input type="button" value="添加" id="save" />
</form>

@section footerjs{
    <script src="~/js/Validform_v5.3.2.js"></script>
    <script type="text/javascript">
        function add() {
            var fromData = $('#formData').serializeArray();
            $.ajax({
                url: '/Role/Add',
                data: fromData,
                dataType: 'json',
                type: 'post',
                success: function (res) {
                    if (res.status == 'ok') {
                        parent.location.reload();
                    } else {
                        alert(res.errorMsg);
                    }
                },
                error: function () {
                    alert('网络请求错误');
                }
            })
        }
        $(function () {
            var demo = $("#formData").Validform({ tiptype: 2 });
            $('#save').click(function () {
                if (demo.check(false)) {
                    add();
                }
            })
        })
    </script>
}
